/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treeship.core.ship.space.impl;

import treeship.core.ship.space.Position;
import treeship.core.ship.space.Shape;

/**
 *
 * @author Moonchild
 */
public class Shape1D extends Shape {

    @Override
    public boolean fitsIn(Shape s) {
        return dimensionFitsInOtherFreespace(s);
    }

    @Override
    public boolean contains(Position p) {
        Position1D p1 = (Position1D) p;
        if (p1.getX() <= getDimension().getValue()) {
            return true;
        }
        return false;
    }

    @Override
    public Position adjustPositionForInnerShape(Position newPos, Shape shape) {
        Position1D p1 = (Position1D) newPos;
        Shape1D shape1 = (Shape1D) shape;
        if (shape1.getDimension().getValue() + newPos.getX() > getDimension().getValue()) {
            double val = getDimension().getValue() - shape1.getDimension().getValue();
            return new Position1D(val);
        } else {
            return p1;
        }
    }
}
